from orm.entity.Chat import Chat
from sqlConfig import DBSession


def getChats(dormitoryId):
    session = DBSession()
    chats = session.query(Chat).filter_by(dormitoryID=dormitoryId).order_by(Chat.chatID.desc()).limit(10).all()[::-1]
    session.close()
    return chats


def getAllChats(dormitoryId):
    session = DBSession()
    chats = session.query(Chat).filter_by(dormitoryID=dormitoryId).all()
    session.close()
    return chats


def makeChat(chat):
    session = DBSession()
    session.add(chat)
    session.commit()
    session.close()


